﻿using System.Windows.Controls;

namespace zaklad_rtv
{
    public abstract class AbstractForm : UserControl
    {
        private IDatabaseObject _editObject;

        public MainWindow MainWindow { get; set; }
        public IDatabaseObject EditObject
        {
            get { return _editObject; }
            set
            {
                _editObject = value;
                if (_editObject != null)
                {
                    FillFormFromObject();
                }
                else
                {
                    ResetForm();
                }
            }
        }

        protected abstract void ResetForm();
        protected abstract void FillFormFromObject();
        protected abstract bool ValidateForm();

        public event DatabaseObjectChangedEventHandler DatabaseObjectChanged
        {
            add { AddHandler(AppEvents.DatabaseObjectChangedEvent, value); }
            remove { RemoveHandler(AppEvents.DatabaseObjectChangedEvent, value); }
        }
    }
}
